← Writeups

SQL injection UNION attack, determining the number of columns returned by the query

https://portswigger.net/web-security/sql-injection/union-attacks/lab-determine-number-of-columns

This lab contains a SQL injection vulnerability in the product category filter. The results from the query are returned in the application's response, so you can use a UNION attack to retrieve data from other tables. The first step of such an attack is to determine the number of columns that are being returned by the query. You will then use this technique in subsequent labs to construct the full attack.

To solve the lab, determine the number of columns returned by the query by performing a SQL injection UNION attack that returns an additional row containing null values.


https://siunam321.github.io/ctf/portswigger-labs/SQL-Injection/sqli-3/

Obtener el numero de columnas: Metodo 1: mediante order by 4 da un error 500 pero con 3 nos lista ningun error

/filter?category=' ORDER BY 3-- -

Metodo 2: utilizando la clausula UNION da error:

/filter?category=' UNION SELECT NULL,NULL,NULL,NULL-- -

no da error:

/filter?category=' UNION SELECT NULL,NULL,NULL-- -